﻿Ext.define('SmartClient.view.ProductsAmountPopupView',
   {
      extend: 'Ext.window.Window',
      controller: 'SmartClient.controller.ProductsAmountPopupController',
      title: 'Select amount',
      width: 150,
      id: 'productsAmountPopup',
      bodyPadding: 5,
      resizable: false,

      config:
         {
            productId: null,
            availableAmount: 0
         },

      initComponent: function ()
      {
         this.productId = this.initialConfig.productId;
         this.availableAmount = this.initialConfig.availableAmount;
         this.callParent(arguments);
         var textField = this.down('textfield');
         textField.vtype = this.initialConfig.textFieldVtype;
         textField.setValue(this.initialConfig.textFieldValue);
         this.down('label').setText(this.initialConfig.units);
      },

      items:
         {
            xtype: 'form',
            layout:
               {
                  type: 'hbox',
                  align: 'middle'
               },
            buttonAlign: 'center',
            items:
               [
                  {
                     xtype: 'textfield',
                     itemId: 'amountTextfield',
                     name: 'amount',
                     allowBlank: false,  // requires a non-empty value
                     enableKeyEvents: true,
                     flex: 1
                  },
                  {
                     xtype: 'label',
                     itemId: 'unitsLabel',
                     padding: '0, 5, 3, 5' // top, right, bottom, left
                  }
               ],
            buttons:
               [
                  {
                     text: 'OK',
                     itemId: 'okButton',
                     formBind: true, //only enabled once the form is valid
                     disabled: true
                  }
               ]
         },

      listeners:
      {
         show: function (field)
         {
            this.down('textfield').focus(true, 50);
         }
      }
   });